#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

char buf[1 << 18], *fs, *ft;
char ops[1 << 18], *opt = ops, *const opt_end = ops + (1 << 18);
 
inline char getc() { 
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}
 
inline int gn() { 
    int k = 0, f = 1;
    char c = getc();
    for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
    for(; isdigit(c); c = getc()) k = k * 10 + c - '0';
    return k * f;
}
 
inline void out() { 
    fwrite(ops, 1, opt - ops, stdout);
    opt = ops;
}
 
inline void out(int x, char c) { 
    bool f = 0;
    if(x < 0) { 
        x = -x;
        f = 1;
    }
    static char *p = new char[21]();
    *(++p) = c;
    do { 
        *(++p) = x % 10 | 0x30;
        x /= 10;
    } while(x);
    if(f) *(++p) = '-';
    while(*p) { 
        *(opt++) = *(p--);
        if(opt == opt_end) out();
    }
}

const int MAXN = 1000003;

int mx[MAXN], a[MAXN], sum;
vector<int> to[MAXN];

void dfs(int x) {
    sum += a[x];
    mx[x] = a[x];
    for(int i = 0; i < to[x].size(); i++) {
        int v = to[x][i];
        dfs(v);
        mx[x] = max(mx[v] + a[x], mx[x]);
    }
}

int main() {
#define LOCAL
#ifdef LOCAL
    freopen("in", "r", stdin);
#endif
    int n = gn();
    for(int i = 1; i < n; i++) {
        int father = gn(), now = gn();
        to[father].push_back(now);
        a[now] = gn();
    }
    int mx1 = 0, mx2 = 0;
    for(int i = 0; i < to[1].size(); i++) { 
        dfs(to[1][i]);
        if (mx1 < mx[to[1][i]]) { 
            mx2 = mx1;
            mx1 = mx[to[1][i]];
        } else if (mx[to[1][i]] > mx2) mx2 = mx[to[1][i]];
    }
    out(sum - mx1 - mx2, '\n');
    out();
}



/*

        3
       / \
      4   8
     /   / \
    2   9   3
   / \     / \
  1   3   2   3

        3
       / \
      1   11
     /   / \
    1   0   2
   / \     / \
  0   0   0   0

        3
       / \
      4   8
     /   / \
    2   9   3
     \       \
      3       3
       \       \
        1       2

        3
       / \
      4   8
     /   / \
    2   9   3
     \       \
      3       3
       \       \
        1       0


        *
        |
        *
        |
        *
        |
        *
        |
        * 
        |\
        * *
        |  \
        *   *
        |   | \
        *   *  *
        |   |  |
        *   *  *
        |  (2)(3)
        *
       (1)


        *
        |
        *
        |
        *
        |
        *
        |
        * 
        |
        * 
        |  
        *
        | 
        *   
        |   
        *   
        |  
        *
       (1)
         \
          *
          |
          *
          (3)
            \
             *
              \
               *
               |
               *
               |
               *
              (2)
              */
